package com.dhecp.project.purchase.controller;

import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.common.utils.DateUtils;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.layui.GridColumnsPropertyModel;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.business.domain.ProductActive;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.common.domain.ModuleNidAndBid;
import com.dhecp.project.common.service.ModuleNidAndBidService;
import com.dhecp.project.purchase.domain.PurchaseAddress;
import com.dhecp.project.purchase.domain.PurchasePlan;
import com.dhecp.project.purchase.domain.PurchasePlanSon;
import com.dhecp.project.purchase.service.PurchaseAddressService;
import com.dhecp.project.purchase.service.PurchasePlanService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * @program: kjecp
 * @description: 采购订单 控制层
 * @author: hlf
 * @create: 2022-08-15 15:13
 */
@Controller
@RequestMapping("/purchase/purchaseplan")
public class PurchasePlanController extends BaseModuleController {

    private String prefix = "purchase/purchaseplan";
    private String moduleTable = ModuleTable.PURCHASE_PLAN;
    private String moduleTable2 = ModuleTable.PURCHASE_PLAN_SON;
    private String moduleTable_Active = ModuleTable.PRODUCT_ACTIVE;

    @Autowired
    private PurchasePlanService purchaseService;

    @Autowired
    private PurchaseAddressService purchaseAddressService;

    @Autowired
    private ModuleNidAndBidService moduleNidAndBidService;

    @Autowired
    private GridColumnsPropertyModel gridColumnsPropertyModel;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;


    /**
     * @Description: 打开查询列表页
     * @Param: [params]
     * @return: org.springframework.web.servlet.ModelAndView
     * @Author: hlf
     * @date: 2022-08-15 15:42
     */
    @RequiresPermissions("purchase:purchaseplan:view")
    @GetMapping()
    public Map<String, Object> listPage(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        params.put("entity", new PurchasePlan()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("prefix", prefix + "/purchaseplan"); //页面路径
        params.put("toolBarWidth", 0);
        params.put("checkBox", "yes");

        Map<String, Object> mv = this.openListPage(params);
        mv.put("purchase", "purchaseplan");
        return mv;
    }


    /**
     * 打开产品选择页面
     *
     * @param params
     * @return ModelAndView
     * @author DH-Xxj
     */
    @GetMapping("/select2")
    public ModelAndView selectPurchaseList(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable_Active);
        params.put("entity", new ProductActive()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("toolBarWidth", 0);
        if (params.get("pagetype") != null && params.get("pagetype").toString().equalsIgnoreCase("checkbox"))
            params.put("checkBox", "yes");
        else params.put("radio", "yes");
        ModelAndView mv = this.getModelAndView();
        AjaxResult ajaxResult = new AjaxResult();
        Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();
        mv.addObject("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
        mv.addObject("ajaxResult", ajaxResult);
        mv.addObject("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));
        mv.addObject("prefix", prefix);
        mv.addObject("moduleTable", moduleTable_Active);
        mv.addObject("pagetype", params.get("pagetype").toString());
        mv.addObject("fmoduleTable", params.get("fmoduleTable").toString());
        if (params.get("selectedObject") != null && params.get("selectedObject") != "") {
            String selectedObject = params.get("selectedObject").toString();
            mv.addObject("selectedObject", selectedObject);
        }
        mv.setViewName("system/organization/mzjobject_select");
        return mv;
    }


    /**
     * @Description: 打开选择列表
     * @Param: [params]
     * @return: org.springframework.web.servlet.ModelAndView
     * @Author: hlf
     * @date: 2022-08-15 15:42
     */
    @GetMapping("/select")
    public ModelAndView selectList(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        params.put("entity", new PurchasePlan()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("toolBarWidth", 0);
        if (params.get("pagetype") != null && params.get("pagetype").toString().equalsIgnoreCase("checkbox"))
            params.put("checkBox", "yes");
        else params.put("radio", "yes");
        ModelAndView mv = this.getModelAndView();
        AjaxResult ajaxResult = new AjaxResult();
        Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();

        mv.addObject("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
        mv.addObject("ajaxResult", ajaxResult);
        mv.addObject("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));
        mv.addObject("prefix", prefix);
        mv.addObject("moduleTable", moduleTable);
        mv.setViewName("common/select");
        return mv;
    }


    /**
     * @Description: 打开制单页
     * @Param: nid 必要参数：单据编码（新增时传默认值 0 ，修改、查看时传单据实际值）
     * @return: org.springframework.web.servlet.ModelAndView
     * @Author: hlf
     * @date: 2022-08-15 15:42
     */
    @RequiresPermissions("purchase:purchaseplan:view")
    @GetMapping("/edit")
    public Map<String, Object> editPage(@RequestParam Map<String, Object> params) {
        if (params.get("nid") == null || params.get("nid") == "") {
            params.put("nid", "0");
        }
        params.put("moduleTable", moduleTable);
        params.put("entity", new PurchasePlan()); //用于获取实体属性名取代对应字典字段名，解决大小写敏感问题
        params.put("moduleUrl", prefix); //页面上级路径
        params.put("prefix", prefix + "/purchaseplan_edit"); //页面路径
        Subject userSubject = ShiroUtils.getSubject();
        int enableEdit = 0;
        boolean vType = false;
        if (params.get(enableEdit) == null || "1".equals(params.get(enableEdit).toString())) {
            if (userSubject.isPermitted("purchase:purchaseplan:edit")) { //当前登录用户主体是否有修改的权限
                enableEdit = 1;
            }
        }

        try {
            Map<String, Object> headData = new HashMap<String, Object>();        //表头的业务数据
//          SysModuleSet moduleSet = sysModuleSetService.queryModuleSet(params);//单据设置信息
            PurchasePlan businessData = purchaseService.queryFirstRecord(params);
            if (businessData == null) { //未查询到对应单据，页面初始化值
                ModuleNidAndBid moduleNidAndBid = moduleNidAndBidService.queryModuleNidAndBidInitial(params);
                PurchaseAddress purchaseAddress = purchaseAddressService.getTop1();
                PurchasePlan purchaseData = new PurchasePlan();
                purchaseData.setNid("0");
                purchaseData.setBid(moduleNidAndBid.getBid());
                purchaseData.setCreateTime(new Date());
                purchaseData.setCid(ShiroUtils.getMandatorCid());
                purchaseData.setCidName(ShiroUtils.getMandatorCidName());
                purchaseData.setbUser(ShiroUtils.getMandatorId());
                purchaseData.setbUserName(ShiroUtils.getMandatorName());
                purchaseData.setbDept(ShiroUtils.getMandatorDeptPath());
                purchaseData.setbDeptName(ShiroUtils.getMandatorDeptName());
                purchaseData.setbPosition(ShiroUtils.getMandatorPositionNameDa());
                purchaseData.setaUser(ShiroUtils.getUserId());
                purchaseData.setaUserName(ShiroUtils.getUserName());
                purchaseData.setaDept(ShiroUtils.getUserDeptPath());
                purchaseData.setaDeptName(ShiroUtils.getUserDeptName());
                purchaseData.setaPosition(ShiroUtils.getUserPositionNameDa());
                purchaseData.setSort("线上");
                purchaseData.setvGsDz(purchaseAddress.getAddress());//获取默认地址
                purchaseData.setAddressId(purchaseAddress.getGuid());
                purchaseData.setIsJp("否");
                headData = TypeUtils.entityToMap(purchaseData);
            } else {
                headData = TypeUtils.entityToMap(businessData);
                vType = businessData.getEffectStock();
            }
            params.put("headData", headData); //表头的业务数据

            params.put("checkBox", "yes"); //生成表格gridColumns时包含复选
            Map<String, Object> mv = this.openEditPage(params);
            mv.put("nowTimeStr", DateUtils.getDate());    //当前日期
            mv.put("enableEdit", vType ? 0 : enableEdit); //当前页面是否可编辑（0：不可编辑，1：可编辑）
            if (businessData != null) {
                Map<String, Object> params2 = new HashMap<String, Object>();
                params2.put("moduleTable", moduleTable);
                params2.put("nid", businessData.getNid());
                mv.put("List", purchaseService.queryListByNid(params2));//母件数据
                mv.put("sonList", purchaseService.querySonListNid(businessData.getNid()));//子件数据
            }
            //取商品子件列表网格
            params.put("moduleTable", moduleTable2);
            params.put("entity", new PurchasePlanSon()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
            params.put("readOnly", vType);//生成列是否可编辑
            params.put("toolBarWidth", 0);//操作区
            params.put("getFieldAttributesType", "pageingrid");//pageingrid：网格字段
            mv.put("gridColumnsZJ", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));

            return mv;
        } catch (Exception e) {
            //return this.gotoModelAndViewErrorPage(e.getMessage());    //详细信息
            return new HashMap<String, Object>();    //空信息
        }

    }

    /**
     * @Description: 明细数据
     * @Param: nid 必要参数：当前 单据编码
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:list")
    @GetMapping("/listbynid")
    @ResponseBody
    public TableDataInfo listByNid(@RequestParam Map<String, Object> params) {
        if (params.get("nid") == null || params.get("nid") == "") {
            return getDataTable(MessageUtils.message("module.error.lack.nid"));
        }
        params.put("moduleTable", moduleTable);
        List<PurchasePlan> list = new ArrayList<PurchasePlan>();
        try {
            list = purchaseService.queryListByNid(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }


    /**
     * @Description: 查询页 根据计划单号获取数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:list")
    @GetMapping("/selectPlan")
    @ResponseBody
    public AjaxResult selectPlan(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        List<PurchasePlan> purchasePlans = new ArrayList<PurchasePlan>();
        List<PurchasePlanSon> purchasePlanSons = new ArrayList<PurchasePlanSon>();
        try {
            purchasePlans = purchaseService.queryListByNid(params);
            purchasePlanSons = purchaseService.querySonListNid(params.get("nid").toString());
            ajaxResult.put("plan",purchasePlans);
            ajaxResult.put("planSon",purchasePlanSons);
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     *@Description: 查询前一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult (data.nid 前一单NID， data.bid 前一单BID)
     *@Author: hlf
     *@date: 2022-05-09 11:40
     */
    @RequiresPermissions("purchase:purchaseplan:view")
    @GetMapping("/lastnid")
    @ResponseBody
    public AjaxResult lastNid(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = purchaseService.queryLastNid(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     *@Description: 查询后一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult (data.nid 后一单NID， data.bid 后一单BID)
     *@Author: hlf
     *@date: 2022-05-09 11:40
     */
    @RequiresPermissions("purchase:purchaseplan:view")
    @GetMapping("/nextnid")
    @ResponseBody
    public AjaxResult nextNid(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = purchaseService.queryNextNid(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     * @Description: 查询页 列表数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<PurchasePlan> list = new ArrayList<PurchasePlan>();
        try {
            if (params.get("isOrder")!=null){
                list = purchaseService.queryList2(params);
            }else{
                list = purchaseService.queryList(params);
            }

        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

    /**
     * @Description: 查询页 子列表数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:list")
    @GetMapping("/sonlist")
    @ResponseBody
    public AjaxResult sonlist(@RequestParam Map<String, Object> params) {
        try {
            params.put("moduleTable", moduleTable2);
            params.put("entity", new PurchasePlanSon()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
            params.put("toolBarWidth", 0);
//            if (params.get("pagetype") != null && params.get("pagetype").toString().equalsIgnoreCase("checkbox"))
//                params.put("checkBox", "yes");
//            else params.put("radio", "yes");
            AjaxResult ajaxResult = new AjaxResult();
            Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();
            Map<String, Object> mapList = new HashMap<>();
            mapList.put("sonList", purchaseService.querySonListBm(params));
            mapList.put("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
            mapList.put("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));
            ajaxResult = AjaxResult.success(mapList);
            return ajaxResult;
        } catch (Exception e) {
            return AjaxResult.error(this.getExceptionMessage(e));
        }
    }


    /**
     * @Description: 分组（整单）查询页 列表数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:list")
    @GetMapping("/group/list")
    @ResponseBody
    public TableDataInfo listGroup(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);    //获取网格字段、查询条件字段、数据权限条件字段等
        params.put("jurisdictionModuleTable", moduleTable);    //使用单据moduleTable分配的数据权限
        List<PurchasePlan> list = new ArrayList<PurchasePlan>();
        try {
            list = purchaseService.queryGroupList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }


    /**
     * @Description: 查询已选择的商品
     * @Param: selectedUser ：已选中的商品编号字符串，示例：0000,1001,1002
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-18 17:13
     */
    @GetMapping("/listselect")
    @ResponseBody
    public TableDataInfo userInfoSelectListJson(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<PurchasePlan> list = new ArrayList<PurchasePlan>();
        if (params.get("selectedID") != null && params.get("selectedID") != "") {
            String wherestrhand = "t1.spBm in ('" + params.get("selectedID").toString().replace(",", "','") + "')";
            params.put("wherestrhand", wherestrhand);
            try {
                list = purchaseService.querySelectList(params);
            } catch (Exception e) {
                return getDataTable(this.getExceptionMessage(e).toString());
            }
        } else {
            return getDataTable("请传入已选中的商品编号字符串（selectedUser）");
        }
        return getDataTable(list);
    }



    /**
     * @Description: 查询已选择的计划
     * @Param: selectedUser ：已选中的商品编号字符串，示例：0000,1001,1002
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-18 17:13
     */
    @GetMapping("/listselect2")
    @ResponseBody
    public TableDataInfo planInfoSelectListJson(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<PurchasePlan> list = new ArrayList<PurchasePlan>();
        if (params.get("selectedID") != null && params.get("selectedID") != "") {
            String wherestrhand = "t1.bid in ('" + params.get("selectedID").toString().replace(",", "','") + "')";
            params.put("wherestrhand", wherestrhand);
            try {
                list = purchaseService.querySelectList2(params);
            } catch (Exception e) {
                return getDataTable(this.getExceptionMessage(e).toString());
            }
        } else {
            return getDataTable("请传入已选中的计划单号字符串（selectedID）");
        }
        return getDataTable(list);
    }


    @GetMapping("/listzj2")
    @RequiresPermissions("purchase:purchaseplan:list")
    @ResponseBody
    public TableDataInfo listzj2(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable2);
        List<PurchasePlanSon> list = new ArrayList<PurchasePlanSon>();
        try {
            if (params.get("fBm") != null && params.get("fBm") != "") {
                String wherestrhand = "t1.fBm in ('" + params.get("fBm").toString().replace(",", "','") + "')";
                params.put("wherestrhand", wherestrhand);
                try {
                    list = purchaseService.querySonListByFBm(params);
                } catch (Exception e) {
                    return getDataTable(this.getExceptionMessage(e).toString());
                }
            } else {
                return getDataTable("请传入已选中的用户编号字符串（fBm）");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }


    //根据BID获取采购计划全部子件信息
    @GetMapping("/listzjAll")
    @RequiresPermissions("purchase:purchaseplan:list")
    @ResponseBody
    public TableDataInfo listzjAll(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable2);
        List<PurchasePlanSon> list = new ArrayList<PurchasePlanSon>();
        try {
            if (params.get("bid") != null && params.get("bid") != "") {
                String wherestrhand = "t2.bid in ('" + params.get("bid").toString().replace(",", "','") + "')";
                params.put("wherestrhand", wherestrhand);
                try {
                    list = purchaseService.querySonListByFBm2(params);
                } catch (Exception e) {
                    return getDataTable(this.getExceptionMessage(e).toString());
                }
            } else {
                return getDataTable("请传入已选中的采购计划单号字符串（bid）");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }


    /**
     * @Description: 数据导出Excel
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:export")
    @Log(title = "采购计划数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
        params.put("moduleTable", moduleTable);
        params.put("entity", new PurchasePlan());

        List<PurchasePlan> list = purchaseService.queryList(params);

        params.put("getFieldAttributesType", "export");
        List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<PurchasePlan> util = new ExportExcelUtils<PurchasePlan>(moduleTable, new PurchasePlan());
        return util.exportExcel(list, fieldList, "采购计划数据", "export");
    }


    /**
     * @Description: 导出Excel导入模板
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("purchase:purchaseplan:import")
    @Log(title = "采购计划数据导出", businessType = BusinessType.EXPORT)
    @GetMapping("/exporttemplate")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult exportTemplate(@RequestParam Map<String, Object> params) throws Exception {
        params.put("moduleTable", moduleTable);
        params.put("entity", new PurchasePlan());

        params.put("getFieldAttributesType", "template");
        List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<PurchasePlan> util = new ExportExcelUtils<PurchasePlan>(moduleTable, new PurchasePlan());
        return util.exportExcel(null, fieldList, "采购计划导入模板", "template");
    }


    /**
     * @Description: 保存数据
     * @Param: infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     * @Param: infoItems 必要参数：对应实体类的json格式字符串
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-15 15:44
     */
    @RequiresPermissions(value = {"purchase:purchaseplan:add", "purchase:purchaseplan:edit", "purchase:purchaseplan:delete"}, logical = Logical.OR)
    @Log(title = "采购计划", businessType = BusinessType.UPDATE)
    @PostMapping("/editpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult editSave(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = purchaseService.saveData(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     * @Description: 生成采购订单
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-17 14:55
     */
    @RequiresPermissions("purchase:purchaseplan:edit")
    @Log(title = "生成采购订单", businessType = BusinessType.UPDATE)
    @PostMapping("/createOrder")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult createOrder(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = purchaseService.updateOrder(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }


    /**
     * @Description: 修改审核状态
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-17 14:55
     */
    //@RequiresPermissions("purchase:purchaseplan:edit")
    @Log(title = "修改采购审核状态", businessType = BusinessType.UPDATE)
    @PostMapping("/updateType")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult updateType(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = purchaseService.updateType(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }


    /**
     * @Description: 删除未审核数据
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-17 14:55
     */
    //@RequiresPermissions("purchase:purchaseplan:delete")
    @Log(title = "删除采购计划", businessType = BusinessType.UPDATE)
    @GetMapping("/delete")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult delete(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult = purchaseService.delete(params);
        } catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }



    /**
     * 打开流转页
     * @Param: [params]  fType 必要参数：审核类型（flow_go：流转，flow_back：退回）
     * @Param: [params]  infoMap 必要参数：非网格字段（包括所有显示和隐藏的字段），json格式字符串
     * @return
     * @author DH-Xxj
     */
    @RequiresPermissions("purchase:purchaseplan:flow")
    @PostMapping("/flowpage")
    @ResponseBody
    public AjaxResult flowPage(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        params.put("prefix", prefix);
        return openFlowPage(params);
    }

    /**
     *@Description: 流转
     *@Param: [params] infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     *@Param: [params] infoItems 必要参数：对应实体类的json格式字符串（仅需 guid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 11:42
     */
    //@RequiresPermissions("purchase:purchaseplan:flow")
    @Log(title = "采购订单", businessType = BusinessType.FLOWGO)
    @PostMapping("/flowgopost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult flowGoSave(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult= purchaseService.updateFlowGo(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }

    /**
     *@Description: 退回
     *@Param: [params] infoMap 必要参数：非网格字段（包括头部、底部所有显示和隐藏的字段）
     *@Param: [params] 必要参数：对应实体类的json格式字符串（仅需 guid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 11:42
     */
    //@RequiresPermissions("purchase:purchaseplan:flow")
    @Log(title = "采购订单", businessType = BusinessType.FLOWBACK)
    @PostMapping("/flowbackpost")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult flowBackSave(@RequestParam Map<String, Object> params){
        params.put("moduleTable", moduleTable);
        AjaxResult ajaxResult = new AjaxResult();
        try {
            ajaxResult= purchaseService.updateFlowBack(params);
        }catch (Exception e) {
            ajaxResult = AjaxResult.error(this.getExceptionMessage(e));
        }
        return ajaxResult;
    }



}